﻿using System;
using System.Collections.Generic;

using System.Text;
using Portal.Interface;
using Portal.Environment;
using Portal.Language;

namespace Portal.CMS
{
    public class AddDocument : WebPart
    {
        public override string WebPartId
        {
            get
            {
                return "AddDocument";
            }
        }

        public override string Title
        {
            get
            {
                return ResourceBLL.GetText(WebPartId, "Title", "Thêm mới tài liệu văn bản");
            }
        }

        public override string Description
        {
            get
            {
                return ResourceBLL.GetText(WebPartId, "Description", "");
            }
        }

        public override string RenderWebPart(LoadParamCls loadParamCls)
        {
            AjaxPro.Utility.RegisterTypeForAjax(typeof(AddDocument));
            string belongSite = (string)Environments.Request("belongSite");
            string RetHtml =
                WebPartUtilities.AttachJavascript("Portal.CMS", "Document.js") +
                "<input id=txtBelongSite type=hidden value=\"" + belongSite + "\">" +
                "<table>" +
                "       <tr>" +
                "           <td>" + ResourceBLL.GetText(WebPartId, "Subject", "Tiêu đề") + ":</td>" +
                "           <td><input class=cssTextBoxDialog  id=txtSubject></td>" +
                "       </tr>" +
                "       <tr>" +
                "           <td>" + ResourceBLL.GetText(WebPartId, "Description", "Mô tả") + ":</td>" +
                "           <td><textarea id=txtDescription></textarea></td>" +
                "       </tr>" +
                "       <tr>" +
                "           <td>" + ResourceBLL.GetText(WebPartId, "JumpUrl", "Url") + ":</td>" +
                "           <td><input class=cssTextBoxDialog  id=txtUrl></td>" +
                "       </tr>" +
                "       <tr>" +
                "           <td></td>" +
                "           <td><input onclick=javascript:SaveClientAddDocument(); type=button value=\"" + ResourceBLL.GetText(WebPartId, "saveButton", "Ghi lại") + "\"><input type=button onclick=javascript:window.close(); value=\"" + ResourceBLL.GetText(WebPartId, "CloseButton", "Thoát") + "\"></td>" +
                "       </tr>" +
                "</table>";
            RetHtml = Environments.GetFormDialog(RetHtml, ResourceBLL.GetText(WebPartId, "Title", "Thêm bộ tài liệu"));
            return RetHtml;
        }


        public override void LoadSubControls(System.Web.UI.WebControls.PlaceHolder pl, System.Web.UI.Page Page, LoadParamCls LoadParamCls)
        {

        }



        [AjaxPro.AjaxMethod]
        public string ServerSideAddDocument(string belongSite, string DocumentName, string Description, string JumpUrl)
        {
            try
            {
                Environment.Environments.CheckSessionTimeOut(true);
                if (DocumentName.Trim().Length == 0) throw new Exception(ResourceBLL.GetText(WebPartId, "EnterName", "Nhập tiêu đề!"));
                new DocumentBLL().AddDocument(null, belongSite, Environments.ActiveLanguage, DocumentName, Description, JumpUrl);
                return ResourceBLL.GetText(WebPartId, "MessageAddOk", "Tạo mới thành công!");
            }
            catch (Exception ex)
            {
                return "ERROR: " + ex.Message.ToString();
            }
        }


        [AjaxPro.AjaxMethod]
        public string ProcessHtml(string Html, int Index)
        {
            Html = Html.Replace("<div class=\"cssDivRowItem\" id=\"divRowItem_" + Index + "\"></div>", "");
            return Html;
        }
    }
}